module.exports = function (app, models, $, db, nm) {

    //  新增接口 
    app.post('/v1/index_region', (req, res) => {
        req.body.unitId = req.unitId
        models.index_region.insert(req.body, ret => {

            res.send(ret)
        })
    })
    // 编辑接口
    app.put('/v1/index_region', (req, res) => {
        models.index_region.update({ _id: req.body._id }, req.body, ret => {
            res.send(ret)
        })
    })
    // 删除首页信息
    app.delete('/v1/index_region', (req, res) => {
        models.index_region.remove({ _id: req.query._id }, ret => {
            res.send(ret)
        }, { real: true })
    })
    // 获取详情接口
    app.get('/v1/index_regionInfo', (req, res) => {
        models.index_region.find({ _id: req.query._id }, ret => {
            res.send(ret)
        }), {
            projection: {
                type: 1,
                img: 1,
                url: 1,
                description: 1,

            }
        }
    })

    // 获取接口
    app.get('/v1/index_region', (req, res) => {
        var query = {
            pageSize: req.query.pageSize || 10,
            pageNum: req.query.pageNum || 1,
            type: req.query.type,
            unitId: req.unitId
        }


        models.index_region.list(query, ret => {

            res.send(ret)

        })
    })

    // 小程序获取首页banner列表
    app.get('/index/banners', (req, res) => {
        models.index_region.list({type:'banner'},ret => {
            res.send(ret)
        },{
            sort:{
                createTime:1
            }
        })
    })
    // 小程序获取首页分区列表
    app.get('/index/categorys', (req, res) => {
        models.index_region.list({type:'category'},ret => {
            res.send(ret)
        },{
            sort:{
                createTime:1
            }
        })
    })
    // 小程序获取首页推荐列表
    app.get('/index/recommends', (req, res) => {
        let pageNum = req.query.pageNum || 1;
        models.index_region.list({type:'recommend',pageNum,pageSize:2},ret => {
            res.send(ret)
        },{
            sort:{
                createTime:1
            }
        })
    })
    // 小程序获取首页新闻列表
    app.get('/index/news', (req, res) => {
        models.article.list({hot:1}, ret => {
			res.send(ret)
		},{
            sort:{
                createTime:1
            },
			projection: {
				_id:1,
				type:1,
				img:1,
				title:1,
				digest:1,
				time:1,
				userId:1,
				content:1,
				hot:1,
				status:1
			}
		})
    })
}


